<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" value=""><br>
    <button>求和</button> <span></span>
</body>
<script>
    let ipt = document.getElementsByTagName('input')[0]
    let button = document.getElementsByTagName('button')[0]
    let span = document.getElementsByTagName('span')[0]
    let arr = [1,2,3]
    ipt.value = arr
    button.onclick = function (){
        var sum = 0
        for (let index = 0; index < arr.length; index++) {
             sum += arr[index];
            
        }
        // console.log(sum);
        span.innerHTML = sum
    }
</script>
</html>